﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using HotelManageSystem.Domain.Entities;

namespace HotelManageSystem.Models
{
    public class AttendanceModel
    {
        [Display(Name="编号")]
        public int Id { get; set; }

        [Display(Name = "员工编号")]
        public int EmployeeId { get; set; }

        [Display(Name = "员工姓名")]
        public string Name { get; set; }

        [Display(Name = "所在部门")]
        public string Department { get; set; }

        [Display(Name = "员工职位")]
        public string Post { get; set; }

        [Display(Name = "考勤日期")]
        [Required(ErrorMessage = "必须输入出生日期")]
        [DataType(DataType.Date, ErrorMessage = "必须输入时间")]
        public DateTime AttendDate { get; set; }

        [Display(Name = "上班时间")]
        [Required(ErrorMessage = "必须输入上班时间")]
        [DataType(DataType.Time, ErrorMessage = "必须输入时间")]
        public DateTime StartTime { get; set; }

        [Display(Name = "下班时间")]
        [Required(ErrorMessage = "必须输入下班时间")]
        [DataType(DataType.Time, ErrorMessage = "必须输入时间")]
        public DateTime EndTime { get; set; }

        [Display(Name = "在岗时长")]
        public string OnGuardTime
        {
            get { return GetTimes(); }
        }

        [Display(Name = "员工状态")]
        public string EmployeeStatus { get; set; }

        [Display(Name = "考勤状态")]
        [Required(ErrorMessage = "必须输入考勤状态")]
        public string AttendaceStatus { get; set; }

        [Display(Name = "备注")]
        [StringLength(25, ErrorMessage = "备注不能超过25个字符")]
        public string AttendaceRemark { get; set; }

        private string GetTimes()
        {
            TimeSpan t1 = new TimeSpan(StartTime.Ticks);
            TimeSpan t2 = new TimeSpan(EndTime.Ticks);
            TimeSpan ts = t2.Subtract(t1).Duration();
            if (ts.Minutes == 0)
            {
                return ts.Hours.ToString() + "小时";
            }
            return ts.Hours.ToString() + "小时" + ts.Minutes.ToString() + "分钟";
        }
    }
}